package com.star.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.star.model.KeyNewsModel;
import com.star.model.NewsModel;
import com.star.model.PlModel;
import com.star.service.KeyNewsService;
import com.star.service.NewsDealWithService;
import com.star.service.NewsService;

@Service
public class NewsDealWithServiceImpl implements NewsDealWithService {

	@Autowired
	private KeyNewsService keyNewsService;

	@Autowired
	private NewsService newsService;

	@Override
	public List<NewsModel> queryListContent(Integer keyId, Integer newsId) {
		List<NewsModel> newsList = new ArrayList<NewsModel>();
		KeyNewsModel keyNewsModel = keyNewsService.queryById(keyId);
		if (keyNewsModel != null) {
			List<KeyNewsModel> listKeyNews = keyNewsService.queryContent(keyNewsModel.getContent().substring(0, 4));
			for (KeyNewsModel keyModel : listKeyNews) {
				List<NewsModel> lists = newsService.queryNewsByKeyId(keyModel.getId());
				for (Iterator<NewsModel> iterator = lists.iterator(); iterator.hasNext();) {
					NewsModel model = iterator.next();
					if (newsId.intValue() == model.getId().longValue()) {
						iterator.remove();
						continue;
					}
					newsList.add(model);
				}
			}
		}
		return newsList;
	}

	@Override
	public PlModel queryPlData(Integer newsId) {
		
		return null;
	}

}
